package com.atwisdom.star.exception.pojo;

import lombok.extern.slf4j.Slf4j;

/**
 * 自定义业务异常
 */
@Slf4j
public class BusinessException extends RuntimeException {


    /**
     * 自定义异常枚举类
     */
    private ErrorEnum errorEnum;

    /**
     * 错误码
     */
    private String code;

    /**
     * 错误信息
     */
    private String errorMsg;


    public BusinessException() {
        super();
        this.errorEnum = ErrorEnum.BUSINESS;
        this.code = errorEnum.getCode();
        this.errorMsg = errorEnum.getMsg();
    }
    public BusinessException(Throwable e) {
        super(e);
        this.errorEnum = ErrorEnum.BUSINESS;;
        this.code = errorEnum.getCode();
        this.errorMsg = errorEnum.getMsg();
    }

    public BusinessException(String code, String errorMsg) {
        super("{code:" + code + ",errorMsg:" + errorMsg + "}");
        this.code = code;
        this.errorMsg = errorMsg;
    }

    public BusinessException(int code, String errorMsg) {
        super("{code:" + code + ",errorMsg:" + errorMsg + "}");
        this.code = String.valueOf(code);
        this.errorMsg = errorMsg;
    }

    public BusinessException(String errorMsg) {
        super(errorMsg);
        this.code = ErrorEnum.BUSINESS.getCode();
        this.errorMsg = errorMsg;
    }

    public BusinessException(String code, String errorMsg, Throwable e) {
        super("{code:" + code + ",errorMsg:" + errorMsg + "}", e);
        this.code = code;
        this.errorMsg = errorMsg;
        log.error("business error info: {}", e.getMessage());
    }


    public ErrorEnum getErrorEnum() {
        return errorEnum;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
